package com.example.capturetheflag.createGame;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Spinner;

import com.example.capturetheflag.R;
import com.example.capturetheflag.connection.HttpPostCreateGameRequest;
import com.example.capturetheflag.helper.Singleton;

public class CreateGameActivity extends Activity {
	
	private EditText gameName;
	private EditText playersCount;
	private EditText pointsCount;
	private Dialog dialog;
	private Spinner PointsSpinner, PlayersSpinner;

    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_create_game);
        
        PlayersSpinner = (Spinner)findViewById(R.id.spinnerPlayer);
        PointsSpinner = (Spinner)findViewById(R.id.spinnerPoint);
      
      		List<String> pointsList = new ArrayList<String>();
      		List<String> playersList = new ArrayList<String>();
      		for(int i=1  ; i<=30 ; i++)
      		{
      			pointsList.add("" + i);
      		}
      		for(int i=2  ; i<=10 ; i++)
      		{
      			playersList.add("" + i);
      		}
      		
      		ArrayAdapter<String> playersSpinnerAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, playersList);
      		playersSpinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
      		PlayersSpinner.setAdapter(playersSpinnerAdapter);
    		
    		ArrayAdapter<String> pointsSpinnerAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, pointsList);
    		pointsSpinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    		PointsSpinner.setAdapter(pointsSpinnerAdapter);
    }
    
    public void onButtonNextClick(View view)
    {
    	
	
    	gameName = (EditText)findViewById(R.id.gameName);
		playersCount = (EditText)findViewById(R.id.players);
		pointsCount = (EditText)findViewById(R.id.maxPoints);

		
		Singleton.getInstance().gameID = null;
		
		HttpPostCreateGameRequest httpPostRequest = new HttpPostCreateGameRequest(getApplicationContext(),this);
		httpPostRequest.execute("http://proinz.studentlive.pl/GeoService.svc/CreateGame","CreateGame"
				, gameName.getText().toString(), PlayersSpinner.getSelectedItem().toString(), PointsSpinner.getSelectedItem().toString());
		
		dialog = new Dialog(this);
        dialog.setTitle("Please wait for the connection");
        dialog.show();
        dialog.setCancelable(false);
    }
}
